package android.tong;

import android.R.color;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.RadioGroup;

public class MyRadioButton extends Activity implements android.widget.RadioGroup.OnCheckedChangeListener {

	private final int WC = RadioGroup.LayoutParams.WRAP_CONTENT;
	private RadioGroup rg_Layout;
	private DrawView dv;
	private LinearLayout layout;
	private int myColor = Color.YELLOW;
	private RadioGroup.LayoutParams params;
	private LinearLayout.LayoutParams para;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.Show_Layout_01();
	}

	public OnClickListener listener = new OnClickListener() {
		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			setContentView(rg_Layout);
		}
	};
	
	public void Show_Layout_01() {
		layout = new LinearLayout(this);
		setContentView(layout);
		
		layout.setOrientation(LinearLayout.VERTICAL);
		para = new LinearLayout.LayoutParams(230, 140);
		dv = new DrawView(this);
		layout.addView(dv, para);
		
		Button btn = new Button(this);
		Drawable dw;
		if (myColor == Color.BLUE) 
			dw = this.getResources().getDrawable(R.drawable.android);
		else
			dw = this.getResources().getDrawable(R.drawable.girlandroid);
		btn.setBackgroundDrawable(dw);
		btn.setText("Change Color");
		btn.setOnClickListener(listener);
		para = new LinearLayout.LayoutParams(WC, WC);
		layout.addView(btn, para);
		
		rg_Layout = new RadioGroup(this);
		params = new RadioGroup.LayoutParams(WC, WC);
		rg_Layout.setOrientation(RadioGroup.VERTICAL);
		rg_Layout.setLayoutParams(params);
		rg_Layout.setOnCheckedChangeListener(this);
		
		RadioButton rbtn1 = new RadioButton(this);
		rbtn1.setText("Yellow");
		rbtn1.setId(1001);
		rg_Layout.addView(rbtn1, params);
		
		RadioButton rbtn2 = new RadioButton(this);
		rbtn2.setText("Blue");
		rbtn2.setId(1002);
		rg_Layout.addView(rbtn2, params);
	}

	@Override
	public void onCheckedChanged(RadioGroup arg0, int arg1) {
		// TODO Auto-generated method stub
		if (arg0.getCheckedRadioButtonId() == 1001) 
			myColor = Color.YELLOW;
		else
			myColor = Color.BLUE;
		this.Show_Layout_01();
	}
	
}
